package org.dothwinds.springbootstudy.controller;

import org.dothwinds.springbootstudy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/addUser")
    public String addUser(@RequestParam(value = "name") String name, @RequestParam(value = "addr") String addr, @RequestParam(value = "company") String company){
        int result = userService.add(name, addr, company);
        if (result == 1) {
            return "success";
        } else {
            return "fail";
        }
    }

    @GetMapping("/deleteUser")
    public String deleteUser(@RequestParam(value = "id") long id){
        int result = userService.delete(id);
        if (result == 1) {
            return "success";
        } else {
            return "fail";
        }
    }
}
